<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      document.write("2.计算可以通过多少次路口:");
      var money = 100000;
      var tmp = 0;
      while (money >= 5000) {
        if (money >= 50000) {
          money = parseInt(money * 0.95);
          tmp += 1;
        } else if (money < 50000 && money >= 5000) {
          money -= 5000;
          tmp += 1;
        }
        // document.write(money + " ");
      }
      document.write(tmp + "次");
      document.write("<br>");

      document.write("3.求出1-1/2+1/3-1/4…..1/100的和:");
      var res = 1;
      for (var i = 2; i <= 100; i++) {
        i % 2 == 0 ? (res -= 1 / i) : (res = res + 1 / i);
      }
      document.write(res);
    </script>
  </body>
</html>
